// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.worldMap;

import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Paths;
import java.util.HashMap;
import zombie.core.math.PZMath;

public final class WorldMapImages {
    private static final HashMap<String, WorldMapImages> s_filenameToImages = new HashMap();
    private String m_directory;
    private ImagePyramid m_pyramid;

    public static WorldMapImages getOrCreate(String directory) {
        String string = zombie.ZomboidFileSystem.instance.getString(directory + "/pyramid.zip");
        if (!Files.exists(Paths.get(string), new LinkOption[0])) {
            return null;
        } else {
            WorldMapImages worldMapImages = (WorldMapImages)s_filenameToImages.get(string);
            if (worldMapImages == null) {
                worldMapImages = new WorldMapImages();
                worldMapImages.m_directory = directory;
                worldMapImages.m_pyramid = new ImagePyramid();
                worldMapImages.m_pyramid.setZipFile(string);
                s_filenameToImages.put(string, worldMapImages);
            }

            return worldMapImages;
        }
    }

    public ImagePyramid getPyramid() {
        return this.m_pyramid;
    }

    public int getMinX() {
        return this.m_pyramid.m_minX;
    }

    public int getMinY() {
        return this.m_pyramid.m_minY;
    }

    public int getMaxX() {
        return this.m_pyramid.m_maxX;
    }

    public int getMaxY() {
        return this.m_pyramid.m_maxY;
    }

    public int getZoom(float zoomF) {
        byte _byte = 4;
        if ((double)zoomF >= 16.0) {
            _byte = 0;
        } else if (zoomF >= 15.0F) {
            _byte = 1;
        } else if (zoomF >= 14.0F) {
            _byte = 2;
        } else if (zoomF >= 13.0F) {
            _byte = 3;
        }

        return PZMath.clamp(_byte, this.m_pyramid.m_minZ, this.m_pyramid.m_maxZ);
    }

    public float getResolution() {
        return this.m_pyramid.m_resolution;
    }

    private void destroy() {
        this.m_pyramid.destroy();
    }

    public static void Reset() {
        for (WorldMapImages worldMapImages : s_filenameToImages.values()) {
            worldMapImages.destroy();
        }

        s_filenameToImages.clear();
    }
}
